﻿
#include "user.h"

//这是一个示例函数,
// 我们实际编程的时候，只需要编号自己的函数之后，然后再添加进下面的函数列表中即可
// long CAPLEXPORT far CAPLPASCAL addint(long a,long b)
// {
//   return a+b;
// }

iqueue_t rxQueue={nullptr,0,0,0,0},txQueue={nullptr,0,0,0,0};

i_status CAPLEXPORT far CAPLPASCAL rxQueueInit(uint32_t queueSize)
{
    if(rxQueue.storage==nullptr)
    {
        return iqueue_init(&rxQueue,queueSize,sizeof(CANFrame_t),malloc(queueSize*sizeof(CANFrame_t)));
    }
    else
    {
        iqueue_destroy(&rxQueue);
        return iqueue_init(&rxQueue,queueSize,sizeof(CANFrame_t),malloc(queueSize*sizeof(CANFrame_t)));
    }
}

i_status CAPLEXPORT far CAPLPASCAL txQueueInit(uint32_t queueSize)
{
    if(txQueue.storage==nullptr)
    {
        return iqueue_init(&txQueue,queueSize,sizeof(CANFrame_t),malloc(queueSize*sizeof(CANFrame_t)));
    }
    else
    {
        iqueue_destroy(&txQueue);
        return iqueue_init(&txQueue,queueSize,sizeof(CANFrame_t),malloc(queueSize*sizeof(CANFrame_t)));
    }
}

i_status CAPLEXPORT far CAPLPASCAL rxQueueClear()
{
    return iqueue_clear(&rxQueue);
}

i_status CAPLEXPORT far CAPLPASCAL txQueueClear()
{
    return iqueue_clear(&txQueue);
}

i_status CAPLEXPORT far CAPLPASCAL rxFrame_enqueue(CANFrame_t* frame)
{
    return iqueue_enqueue(&rxQueue,frame);
}
i_status CAPLEXPORT far CAPLPASCAL txFrame_enqueue(CANFrame_t* frame)
{
    return iqueue_enqueue(&txQueue,frame);
}

i_status CAPLEXPORT far CAPLPASCAL rxFrame_dequeue(CANFrame_t* frame)
{
    return iqueue_dequeue(&rxQueue,frame);
}

i_status CAPLEXPORT far CAPLPASCAL txFrame_dequeue(CANFrame_t* frame)
{
    return iqueue_dequeue(&txQueue,frame);
}

// ============================================================================
// CAPL_DLL_INFO_LIST : 输出的函数列表
//   第一个字段是预定义的，不得更改！
//   第二个字段是预定义的，不得更改！
//   列表必须以{0,0}条目结束！
// 新结构支持最多50个字符的函数名称
// ============================================================================
CAPL_DLL_INFO4 table[] = {
{CDLL_VERSION_NAME, (CAPL_FARCALL)CDLL_VERSION, "", "", CAPL_DLL_CDECL, 0xabcd, CDLL_EXPORT },

  {"dllInit",           (CAPL_FARCALL)appInit,          "CAPL_DLL","This function will initialize all callback functions in the CAPLDLL",'V', 1, "D", "", {"handle"}},
  {"dllEnd",            (CAPL_FARCALL)appEnd,           "CAPL_DLL","This function will release the CAPL function handle in the CAPLDLL",'V', 1, "D", "", {"handle"}}, 
//从下面添加需要导出的函数，格式如下
//{导出函数名称,          函数地址,                       函数类别名称,   函数功能描述,           返回值数据类型,  函数参数数量,  参数的数据类型, 参数的维数(几维数组), 函数参数名称}
//   {"test",              (CAPL_FARCALL)test,             "CAPL_DLL","This function will test",       'D',            2,          "BL",         {'\001','\000'},   {"arry","lenth"}},
//   {"addint",            (CAPL_FARCALL)addint,           "CAPL_DLL","This function will add a and b",'L', 2, "LL", "", {"a","b"}},
  {"txQueueInit",       (CAPL_FARCALL)txQueueInit,      "CAPL_DLL","Tx frame queue init",                                               'L', 1, "L", {},       {"FrameQueueSize"}},
  {"rxQueueInit",       (CAPL_FARCALL)rxQueueInit,      "CAPL_DLL","Rx frame queue init",                                               'L', 1, "L", {},       {"FrameQueueSize"}},
  {"txQueueClear",      (CAPL_FARCALL)txQueueClear,    "CAPL_DLL","Tx frame queue clear",                                              'L', 0, "", {},       {}},
  {"rxQueueClear",      (CAPL_FARCALL)rxQueueClear,    "CAPL_DLL","Rx frame queue clear",                                              'L', 0, "", {},       {}},
  {"txFrame_enqueue",   (CAPL_FARCALL)txFrame_enqueue,  "CAPL_DLL","Tx frame enqueue",                                                  'L', 1, "B", {'\001'}, {"FrameStruct_ByteArray"}},
  {"rxFrame_enqueue",   (CAPL_FARCALL)rxFrame_enqueue,  "CAPL_DLL","Rx frame enqueue",                                                  'L', 1, "B", {'\001'}, {"FrameStruct_ByteArray"}},
  {"txFrame_dequeue",   (CAPL_FARCALL)txFrame_dequeue,  "CAPL_DLL","Tx frame dequeue",                                                  'L', 1, "B", {'\001'}, {"FrameStruct_ByteArray"}},
  {"rxFrame_dequeue",   (CAPL_FARCALL)rxFrame_dequeue,  "CAPL_DLL","Rx frame dequeue",                                                  'L', 1, "B", {'\001'}, {"FrameStruct_ByteArray"}},

//{导出函数名称,          函数地址,                       函数类别名称,   函数功能描述,           返回值数据类型,  函数参数数量,  参数的数据类型, 参数的维数(几维数组), 函数参数名称}
{0, 0}
};
CAPLEXPORT CAPL_DLL_INFO4 far * caplDllTable4 = table;
